package com.jy.modules.cims.loan.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.jy.modules.cims.common.CimsConstant;
import com.jy.modules.cims.component.tbj.TBJNoticeService;
import com.jy.modules.cims.data.common.dao.TCMmCooperorgDealDao;
import com.jy.modules.cims.data.dao.RaisePlanDao;
import com.jy.modules.cims.data.dto.DealDto;
import com.jy.modules.cims.data.dto.RaisePlanDto;
import com.jy.modules.cims.data.dto.inter.tbj.jj.NoticeDTO;
/**
 * 募集计划业务层
 * ClassName: RaisePlanService 
 * @Description: TODO
 * @author dell
 * @date 2015-9-8
 */
@Service("com.jy.modules.cims.loan.service.RaisePlanService")
public class RaisePlanService {
	//private static final Logger logger = LoggerFactory.getLogger(RaisePlanService.class);
	
	@Autowired
	private RaisePlanDao raisePlanDao;
	
	@Autowired
	private TCMmCooperorgDealDao tCMmCooperorgDealDao;

	@Autowired
	@Qualifier("com.jy.modules.cims.component.tbj.TBJNoticeService")
	private TBJNoticeService tBJNoticeService;

	/**
	 * 
	 * @Description 获取募集计划 下拉列表 剔除已被占用的募集计划
	 * @param searchParams
	 * @return
	 * @throws Exception   
	 * List<TCMmRaisePlanDTO>  
	 * @throws
	 * @author zhangmi
	 * @date 2015-9-10
	 */
	public List<RaisePlanDto> getSelectRaisePlanList(Map<String,Object> searchParams) throws Exception {
	    List<RaisePlanDto> dataList = raisePlanDao.searchSelectRaisePlan(searchParams);
        return dataList;
    }
	
	/**
	 * 
	 * @Description 获取募集计划 列表所有数据
	 * @param searchParams
	 * @return
	 * @throws Exception   
	 * List<TCMmRaisePlanDTO>  
	 * @throws
	 * @author zhangmi
	 * @date 2015-9-10
	 */
	public List<RaisePlanDto> getRaisePlanList(Map<String,Object> searchParams) throws Exception {
	    List<RaisePlanDto> dataList = raisePlanDao.searchRaisePlanList(searchParams);
        return dataList;
    }
	/**
	 * 
	 * @Description 查询募集计划列表
	 * @param searchParams
	 * @return
	 * @throws Exception   
	 * List<RaisePlanDto>  
	 * @throws
	 * @author zhangmi
	 * @date 2015-9-21
	 */
	public List<RaisePlanDto> queryRaisePlanList(Map<String,Object> searchParams) throws Exception {
	    List<RaisePlanDto> dataList = raisePlanDao.searcRaisePlanListByPaging(searchParams);
        return dataList;
    }
    
    /**
	 * 
	 * @Description 导出募集计划列表
	 * @param searchParams
	 * @return
	 * @throws Exception   
	 * List<RaisePlanDto>  
	 * @throws
	 */
	public List<RaisePlanDto> searcRaisePlanListExport(Map<String,Object> searchParams) throws Exception {
	    List<RaisePlanDto> dataList = raisePlanDao.searcRaisePlanListExport(searchParams);
        return dataList;
    }
    
	/**
	 * 
	 * @Description 修改募集计划状态为完成
	 * @param planId   
	 * void  
	 * @throws
	 * @author zhangmi
	 * @date 2015-9-10
	 */
	public void updateRaisePlanFinishByPlanIds(String planId){

		Map<String, Object> searchParams = new HashMap<String, Object>();
		searchParams.put("planIds", planId);
		searchParams.put("status", CimsConstant.RAISE_STATUS_END);
		raisePlanDao.updateRaisePlanByPlanIds(searchParams);
	}
	
	/**
	 * 
	 * @Description 
	 * @param planId 修改交易状态 和募集状态 并发送通知
	 * @param dto   交易dto
	 * void  
	 * @throws
	 * @author zhangmi
	 * @date 2015-9-19
	 */
	public void updateCooperorgDealAndRaisePlan(String planId,DealDto dto){
		//修改交易状态为03
		Map<String, Object> paramMap = new HashMap<String, Object>();
		dto.setCooperativeAgencyDealStatus(CimsConstant.DEAL_STATUS_FINISH);
		paramMap.put("dto", dto);
		tCMmCooperorgDealDao.updateTCMmCooperorgDeal(paramMap);
		//修改募集计划状态为02 募集完成
		Map<String, Object> searchParams = new HashMap<String, Object>();
		searchParams.put("planIds", planId);
		searchParams.put("status", CimsConstant.RAISE_STATUS_END);
		raisePlanDao.updateRaisePlanByPlanIds(searchParams);
		//铜板街发送消息
		NoticeDTO notice = new NoticeDTO();
		notice.setPlanId(planId);
		notice.setPlanStatus(1);
		tBJNoticeService.noticeTBJ(notice); 
	}
	
	/**
     * 
     * @Description 根据募集编号查询进件信息 状态 T_C_MM_LOAN_DETAIL.loan_each_status <>04
     * @param searchParams
     * @return   
     * List<RaisePlanDto>  
     * @throws
     * @author zhangmi
     * @date 2015-9-25
     */
	public List<RaisePlanDto> searchJjMsgByPlanId(Map<String,Object> searchParams) throws Exception {
	    List<RaisePlanDto> dataList = raisePlanDao.searchJjMsgByPlanId(searchParams);
        return dataList;
    }
}
